package me.zk.practice1.hw;

import java.util.*;

public class HWBJJ21 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int[] a1 = Arrays.stream(scanner.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();

        int[] a2 = Arrays.stream(scanner.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();

        Map<Integer,Integer> m1 = new HashMap<>();
        Map<Integer,Integer> m2 = new HashMap<>();
        get(a1,m1);
        get(a2,m2);
        Set<Integer> s1 = m1.keySet();
        Set<Integer> s2 = m2.keySet();
        Set<Integer> s3 = new HashSet<>(s1);
        s3.retainAll(s2);
        if (s3.isEmpty()) {
            System.out.println("NULL");
            return;
        }
        Map<Integer,List<Integer>> map = new TreeMap<>();
        for (int t : s3) {
            int key = Math.min(m1.get(t),m2.get(t));
            List<Integer> list = map.getOrDefault(key,new ArrayList<Integer>());
            list.add(t);
            map.put(key,list);
        }
        for (Integer key : map.keySet()) {
            List<Integer> list = map.get(key);
            StringBuffer sb = new StringBuffer(key +":");
            for (int i = 0; i < list.size(); i++) {
                sb.append(list.get(i));
                if (i != list.size()-1){
                    sb.append(",");
                }
            }
            System.out.println(sb);

        }


    }

    public static void get(int[] nums,  Map<Integer,Integer> map) {
        for (int n :nums) {
            map.put(n,map.getOrDefault(n,0)+1);
        }
    }
}
